//
//  ChangePasswordViewController.m
//  cityStar
//
//  Created by joyban on 14-12-27.
//  Copyright (c) 2014年 tiny. All rights reserved.
//

#import "ChangePasswordViewController.h"

#import "FindPassWordViewController.h"

@interface ChangePasswordViewController ()<UITextFieldDelegate>

@property (weak, nonatomic) IBOutlet UITextField *OldPassword;
@property (weak, nonatomic) IBOutlet UITextField *NewPassword;
@property (weak, nonatomic) IBOutlet UITextField *SecendNewPassword;
@property (weak, nonatomic) IBOutlet UIButton *quedinBtn;

@end

@implementation ChangePasswordViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"修改密码";
    [self addBackButton];
    __weak typeof(self)weakSelf = self;
    [self addRightButtonWithTitle:@"找回密码" actionBlock:^{
        FindPassWordViewController *findPassword = [[FindPassWordViewController alloc]init];
        [weakSelf.navigationController pushViewController:findPassword animated:YES];
    }];
    self.quedinBtn.layer.cornerRadius = 4;
    self.OldPassword.placeholder = @"请输入原密码";
    self.NewPassword.placeholder = @"请输入新密码";
    self.SecendNewPassword.placeholder = @"请重复输入新密码";
    
    self.OldPassword.returnKeyType = UIReturnKeyDone;
    self.OldPassword.delegate = self;
    self.NewPassword.returnKeyType = UIReturnKeyDone;
    self.NewPassword.delegate = self;
    self.SecendNewPassword.returnKeyType = UIReturnKeyDone;
    self.SecendNewPassword.delegate = self;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}

- (void)addRightButtonWithTitle:(NSString *)title actionBlock:(void(^)(void))block
{
    UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [rightButton setFrame:CGRectMake(0, 0, 65, 20)];
    rightButton.titleLabel.font = [UIFont systemFontOfSize:15];
    [rightButton setTitle:title forState:UIControlStateNormal];
    [rightButton setTitleColor:[UIColor colorWithRed:0.991 green:0.532 blue:0.303 alpha:1.000] forState:UIControlStateHighlighted];
    [rightButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [rightButton addTarget:self action:@selector(rightBar_Touched:) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightButton];
    self.rightBarActionBlock = block;
    self.navigationItem.rightBarButtonItem = rightBarButtonItem;
}


#pragma - mark textDeletage

-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    return YES;
}

- (IBAction)didPassword_Action:(id)sender {
    if([self.OldPassword.text isEqualToString:@""])
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"原密码不能为空" delegate:self cancelButtonTitle:@"确认" otherButtonTitles: nil];
        [alert show];
    }else if([self.NewPassword.text isEqualToString:@""])
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"新密码不能为空" delegate:self cancelButtonTitle:@"确认" otherButtonTitles: nil];
        [alert show];
    }else if ([self.SecendNewPassword.text isEqualToString:@""])
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"再一次输入新密码不能为空" delegate:self cancelButtonTitle:@"确认" otherButtonTitles: nil];
        [alert show];
    }else if(![self.NewPassword.text isEqualToString: self.SecendNewPassword.text])
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"两次新密码不一致空" delegate:self cancelButtonTitle:@"确认" otherButtonTitles: nil];
        [alert show];
    }else{
        
    }
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self.OldPassword resignFirstResponder];
    [self.NewPassword resignFirstResponder];
    [self.SecendNewPassword resignFirstResponder];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
